package com.lzj.gen.jetbrains;

/**
 * 主程序
 */
public class FuckJB {

    public static void main(String[] args) throws Exception {
        String baseDir = "D:\\jetbra\\";
        String certFile = baseDir + "\\ca.crt";
        String keyFile = baseDir + "\\ca.key";
        String powerConfigDir = "D:/jetbra/config-jetbrains";

        //生成证书及power.conf配置文件，只需要生成一次即可，后续不需要再生成
//        genCertAndConfig(certFile, keyFile, powerConfigDir);

        //生成全家桶授权证书  // licenseeName 可以自定义
        System.out.println("----开始组建liscense----");
        String license = LicenseUtil.genLicenseForAll("jiang", "2099-09-09");
        System.out.println("----组建liscense = " + license);
        //生成激码
        System.out.println("----开始生成激码----");
        String activeCode = CodeUtil.genActiveCode(certFile, keyFile, license);
        System.out.println("----生成激码成功----");

        System.out.println("activeCode:");
        System.out.println(activeCode);
    }

    /**
     * 生成证书、power.conf配置及激活码
     * @param certFile
     * @param keyFile
     * @param powerConfigBase
     * @param license
     * @return
     * @throws Exception
     */
    private static String genAll(String certFile, String keyFile, String powerConfigBase, String license) throws Exception {
        genCertAndConfig(certFile, keyFile, powerConfigBase);
        return CodeUtil.genActiveCode(certFile, keyFile, license);
    }

    /**
     * 生成证书及power.conf配置
     * @param certFile
     * @param keyFile
     * @param powerConfigBase
     * @throws Exception
     */
    private static void genCertAndConfig(String certFile, String keyFile, String powerConfigBase) throws Exception {
        System.out.println("----开始生成证书----");
        CertUtil.genCert(certFile, keyFile);
        System.out.println("----生成证书结束----");

        System.out.println("----开始生成power.conf配置----");
        PowerConfigUtil.genPowerPluginConfig(certFile, powerConfigBase);
        System.out.println("----生成power.conf配置结束----");
    }

}
